class symbol(object):
    """a class of symbol objects"""

    def __init__(self, name):
        self.name = name
    
    def __eq__(self, other):
        return self.name.__eq__(other.name)

    def __repr__(self):
        return 'S:'+self.name

def define_syms(*symbols):
    """a decorator that lets your the input function have a list
       of symbols"""
    
    def decorator(old_func):
 
        def new_func(*args, **kwargs):

            #initalize symbols
            #keep track of overriden variables
            old_globals = {}
            none_globals = {}
            f_globals = old_func.func_globals
            for key in symbols:
                if f_globals.has_key(key):
                    old_globals[key] = f_globals[key]
                else:
                    none_globals[key] = True
                f_globals[key] = symbol(key)

            try:
                ret_val = old_func(*args, **kwargs)
            
            finally:
                #restore previous globals
                for key in old_globals:
                    f_globals[key] = old_globals[key]
                for key in none_globals:
                    del f_globals[key]
        
            return ret_val
        return new_func
    return decorator 
